﻿/*
 * KLF Headless Browser
 * Written by Kris Oye <kristianoye@gmail.com>
 * Copyright (C) 2011-2012.  All rights reserved.
 */
namespace KLF.Lib.Browser.DOM
{
    #region Using Statements

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    #endregion

    public class NodeList
    {
        #region Properties

        public List<Node> Nodes { get; set; }

        #endregion

        #region Constructors

        internal NodeList(IEnumerable<Node> _nodes)
        {
            Nodes = new List<Node>(_nodes);
        }

        #endregion

        #region DOM Level 1 Compliance

        public Node item(int index)
        {
            return (index > -1 && index < Nodes.Count ? Nodes[index] : null);
        }

        public int length { get { return Nodes.Count; } } 

        #endregion

        /// <summary>
        /// Returns an item from the list when the list is referenced 
        /// as an areay.  This is the same as calling list.item(n)
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public Node this[int index]
        {
            get
            {
                return item(index);
            }
        }
    }
}
